<template>
	<view class="box">
		<view class="search">
			<u-search color="#FFF2CC" searchIconColor="#FFF2CC" placeholderColor="#eee" @change="change"
				@clear="clear" placeholder="输入" bgColor=" #283b65" v-model="keyword" :showAction="false"></u-search>
		</view>
		<view class="box_body">
			<view class="body_item" @click="todetail(item._id)" v-for="item in infolist" :key="item._id">
				<u-icon name="search" color="#FFF2CC" size="28"></u-icon>
				<text class="title">{{item.title}}</text>
			</view>
		</view>
		<u-loadmore v-if="islodaing" :status="status" />
	</view>
</template>

<script>
	const db = uniCloud.database()
	const cmd = db.command
	export default {
		data() {
			return {
				keyword: '',
				timer: null,
				infolist:[],
				status:'loading',
				islodaing:false,
				isclear:false
			};
		},
		methods: {
			clear(){
				this.islodaing=false
				this.infolist=[]
				console.log('ss')
			},
			//转到详情页
			todetail(e){
				uni.navigateTo({
					url:`/pages_video/video-detail/video-detail?_id=${e}`
				})
			},
			change(e) {
				this.islodaing=true
				clearTimeout(this.timer)
				this.timer = setTimeout(() => {
					console.log(e)
					this.searchs(e)

				}, 500)
			},
			//搜索
			async searchs(e) {
				if (e.trim() == "") {
						this.islodaing=false
					this.infolist=[]
					return;
				}
				const text = new RegExp(e, 'g')
				
				await db.collection("video-articles").where(
					cmd.or({
						title: text
					})
				).get().then(res => {
					if(res.result.data.length==0){
						this.status='nomore'
						
					}else{
						this.infolist=[]
						this.islodaing=false
					}
					console.log(res, '索索')
					
					this.infolist=res.result.data
				})
			}
		}
	}
</script>

<style lang="scss">
	.box {
		.search {
			margin-top: 10rpx;
		}

		.box_body {
			margin-top: 20rpx;

			.body_item {
				padding: 10rpx;
				border-bottom: 1px solid #FFF2CC;
				display: flex;
				align-items: center;
				.title{
					margin-left: 20rpx;
					color:#FFF2CC;
					font-size: 25rpx;
					word-break: break-all;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 1;
					overflow: hidden;
				}
			}
		}
	}
</style>
<style>
	page {
		background-color: #11265c;
	}
</style>